<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width" />
    <title>地图导航</title>
    <style>
      * {
        margin: 0;
        padding: 0px;
      }
      html,
      body,
      #container {
        width: 100%;
        height: 100%;
        background-color: #ccc;
      }
    </style>
  </head>
  <body>
    <div id="container"></div>
    <script type="text/javascript">
      window._AMapSecurityConfig = {
        securityJsCode: '2c45f22bb70bb2d9339020a88986c972'
      }
    </script>
    <script type="text/javascript" src="https://webapi.amap.com/maps?v=2.0&key=a74729742a196214e01697e3aa6a699c"></script>
    <script type="text/javascript">
      var map = new AMap.Map('container', {
        viewMode: '3D', // 默认使用 2D 模式，如果希望使用带有俯仰角的 3D 模式，请设置 viewMode: '3D'
        zoom: 18, // 初始化地图层级
        center: [114.227696, 22.726783] // 初始化地图中心点
      })

      window.onload = function () {
        //页面加载完成调用当前位置函数
        window.swift.getCurrentLocation()
      }

      function getLocation(lon, lat) {
        map.setZoomAndCenter(18, [lon, lat]) //同时设置地图层级与中心点
        // window.swift.alert(lon,lat)

        // 获取附近坐标
        map.plugin(['AMap.PlaceSearch'], function () {
          const placeSearch = new AMap.PlaceSearch({
            pageSize: 4, //单页显示结果条数
            pageIndex: 1, //页码
            map: map, //展现结果的地图实例
            extensions: 'base' //返回信息详略，默认为base（基本信息）
          })
          placeSearch.searchNearBy('街道', new AMap.LngLat(lon, lat))
          AMap.Event.addListener(placeSearch, 'complete', res => {
            window.swift.receiveDate(JSON.stringify(res?.poiList?.pois || []))
          })

          AMap.Event.addListener(placeSearch, 'error', err => {
            window.swift.receiveDate('失败' + JSON.stringify(err))
          })
        })
      }
    </script>
  </body>
</html>
